package repository.relsys.services;

import java.util.Collection;
import java.util.Iterator;

import repository.relsys.domainmodel.general.*;

import repository.relsys.services.datacentral.FileDataProvider;
import repository.relsys.services.datacentral.RepositoryDataProvider;
import repository.relsys.services.spring.RelsysResourceFactory;

public class RelsysFileExportImport extends DefaultRelsysService {

	public RelsysFileExportImport() throws InstantiationException, IllegalAccessException, ClassNotFoundException {

		dataProvider = new RepositoryDataProvider();
		initialize();

	}

	@SuppressWarnings("unchecked")
	public <T extends Resource> T loadResourceFromFile(Class<T> clazz) throws Exception {

		RelsysResourceFactory rf = new RelsysResourceFactory();

		Collection<T> c = (Collection<T>) loadAllResources(rf
				.getBeanImplementationClass(clazz), true);

		Iterator<T> iter = c.iterator();

		return iter.next();

	}


	
	public <T extends Resource> void saveResource(T resource) throws Exception {

		saveResource(resource, true);
	}



}
